package chess_game_5;

import java.util.ArrayList;
import java.util.List;

//原lab3 ChessBoardManager类，为了方便改了名
//游戏管理
public class GameManager {
    private final List<Game> games;
    private int currentGameIndex;

    public GameManager() {
        games = new ArrayList<>();
        // 初始3局游戏
        games.add(new PeaceGame("张三", "李四", 1));
        games.add(new ReversiGame("张三", "李四", 2));
        games.add(new GomokuGame("张三", "李四", 3)); // 新增Gomoku
        currentGameIndex = 0;
    }

    public void addGame(String mode, String player1, String player2) {
        int newId = games.size() + 1;

        switch (mode.toLowerCase()) {
            case "peace":
                games.add(new PeaceGame(player1, player2, newId));
                break;
            case "reversi":
                games.add(new ReversiGame(player1, player2, newId));
                break;
            case "gomoku":
                games.add(new GomokuGame(player1, player2, newId)); // 支持添加Gomoku
                break;
            default:
                break;
        }
        // 更改条件语句逻辑，采用更清晰的 switch 结构
        /*
         * if (mode.equalsIgnoreCase("peace")) {
         * games.add(new PeaceGame(player1, player2, newId));
         * }
         * else if (mode.equalsIgnoreCase("reversi")) {
         * games.add(new ReversiGame(player1, player2, newId));
         * }
         */
    }

    public boolean switchGame(int gameId) {
        if (gameId < 1 || gameId > games.size())
            return false;
        currentGameIndex = gameId - 1;
        return true;
    }

    public Game getCurrentGame() {
        return games.get(currentGameIndex);
    }

    public List<Game> getGames() {
        return games;
    }
}